<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>盘点审核</title>
    <link rel="stylesheet" href="/webjars/element-ui/2.15.13/lib/theme-chalk/index.css">
    <script src="/webjars/vue/2.6.14/dist/vue.js"></script>
    <script src="/webjars/element-ui/2.15.13/lib/index.js"></script>
    <script src="/webjars/axios/1.6.2/dist/axios.js"></script>
</head>
<body>
<div id="pan">
    <div>
        <el-form inline>
            <span class="demonstration">审核日期:</span>
            <el-date-picker v-model="dataD"
                            @change="dataTime"
                            type="daterange"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            value-format="yyyy-MM-dd">

            </el-date-picker>
            <el-button type="primary" @click="search" icon="el-icon-search">查询</el-button>
        </el-form>
    </div>
    <template>
        <el-table :data="panlist.data" border style="width: 100%">
            <el-table-column prop="seId" label="编号" width="120"></el-table-column>
            <el-table-column prop="seInventorycheck" label="盘点单号" width="140"></el-table-column>
            <el-table-column prop="name" label="零件名称" width="140"></el-table-column>
            <el-table-column prop="shiNum" label="账面库存" width="140"></el-table-column>
            <el-table-column prop="bianNum" label="实际库存" width="140"></el-table-column>
            <el-table-column prop="seGainlossquantity" label="盈亏数量" width="140"></el-table-column>
            <el-table-column prop="seData" label="审核日期" width="140"></el-table-column>
            <el-table-column prop="seCheckstatus" label="审核状态" width="140">
                <template slot-scope="scope">
                    <span>
                        {{scope.row.seCheckstatus == 1 ? '已通过' : (scope.row.seCheckstatus === 0 ? '未通过' : null) }}
                    </span>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="{row}">
                    <el-button
                            @click="houstlist(row)"
                            size="medium"
                            :disabled="row.seCheckstatus !== null"
                    >补仓
                    </el-button>
                    <el-button
                            type="danger"
                            @click="edithoust(row)"
                            size="medium"
                            :disabled="row.seCheckstatus !== null"
                    >修正
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <!--        分页-->
        <el-pagination
                :page-sizes="[3,6,9]"
                :current-page.sync="vo.pageNo"
                :page-size.sync="vo.pageSize"
                @current-change="search"
                @size-change="search"
                background
                layout="prev, pager, next,sizes"
                :total="panlist.count">
        </el-pagination>
    </template>
</div>


<script>
    new Vue({
        el: "#pan",
        data: {
            panlist: [],
            dataD: [],
            vo: {
                pageNo: 1,
                pageSize: 6,
                seData: '',
                comeTime: '',
            },
            addh: {
                name: '',
                seCheckstatus: '',
                seGainlossquantity: '',
                seData: '',
                seCheckstatus: '',
                seId: ''
            },
            updateRow: {},
            listRow: {},
            number: '',
            seId: {}
        },
        methods: {
            search() {
                axios.get("/pan/xiansearch", {params: this.vo})
                    .then(({data}) => {
                        this.panlist = data;
                    })
            },
            //查询日期
            dataTime(value) {
                if (value === null) {
                    // 可以选择设置默认值或者清除原有的值
                    this.vo.seData = null
                    this.vo.comeTime = null
                } else if (Array.isArray(value) && value.length >= 2) {
                    const [seData, comeTime] = value
                    this.vo.seData = seData
                    this.vo.comeTime = comeTime
                } else {
                    console.error("Invalid value format for dataTime:", value)
                }
            },
            //添加补仓
            houstlist(row) {
                this.addh= row
                this.addh.seCheckstatus = row.seCheckstatus = 0; // 修改状态为 0

                console.log(this.addh)
                axios.post("/pan/addhouse", this.addh)
                    .then(({data}) => {
                        this.$message({
                            message: data.msg,
                            type: data.code == 200 ? 'success' : 'error'
                        });
                        this.search();
                    })
            },
            //修改
            edithoust(row) {
                this.updateRow = row
                this.updateRow.shiNum = this.updateRow.bianNum
                this.addh.seCheckstatus = row.seCheckstatus = 1; // 修改状态为 0
                axios.put("/pan/update", this.updateRow)
                    .then(({data}) => {
                        this.$message({
                            message: data.msg,
                            type: data.code == 200 ? 'success' : 'error'
                        });
                        this.search();
                    })
            },

        },
        mounted() {
            this.search();
        }
    })
</script>
</body>
</html>